/* Copyright (c) 2009-2010, Sean A.O. Harney <sharney3@gmail.com> */

#ifndef FUZZER_OMF_H
#define FUZZER_OMF_H


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <signal.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdarg.h>
#include <stdint.h>
#include <inttypes.h>
#include <errno.h>
#include <dlfcn.h>
#include <dirent.h>
#include <zip.h>
#include <ffi.h>

#include "random.h"
#include "llist.h"
#include "contrib/hashtbl.h"	/* depends on contrib symlink being there */
#include "expr.h"
#include "expr_eval.h"
#include "symbol_tbl.h"
#include "asl.h"
#include "asl_process.h"
#include "stmt.h"
#include "stmt_process.h"
#include "outputlog.h"
#include "regldg.h"
#include "dictfile.h"
#include "command.h"
#include "dl.h"
#include "debug.h"
#include "atexit.h"
#include "parse.h"
#include "zipdir.h"
#include "socket.h"
//#include "mail.h"
#include "util.h"
#include "memusage.h"

struct st_vm_flag_state {
    bool termination_any;	/* 3 bool same as st_stmt_flag */
    bool termination_signal_any;
    bool termination_exit_any;

    LLIST_P termination_exits;	//llist of int
    LLIST_P termination_signals;	//llist of int
};

// VM state
struct st_vm_state {
    Random_handle random_handle;
    unsigned long perm_count;	//the count of how many perms were processed sucessfully.


    struct st_stmt_fuzzdata *fuzzdata_state;	//reusing same stucts as ASL for fuzzdata and target.
    struct st_stmt_target *target_state;

    struct st_vm_flag_state *flag_state;	//differs from st_stmt_flag
};

struct st_glob {
    int current_target_processes;	//TODO: move to omf_state
    HASHTBL *symbol_tbl_global;
    SYMBOL_TBL_LOCAL_STACK_P symbol_tbl_local_stack;
    EXPR_P current_function_return;	//NULL if not yet returned
    int parser_num_errors;
    char *parser_current_filename;	/* since yyfilename doesn't exist */
    bool parser_current_is_include;
    bool parser_explicit_main;	/* was main declared explicitly? */
    bool validation_mode;
    pid_t omf_pid;
    struct timeval omf_starttime;
    struct st_vm_state vm_state;
};
//prototypes
void vm_state_reset(void);

//globals
struct st_glob glob;


#endif				/* FUZZER_OMF_H */
